<template>
  <div class="nav-header">
    <el-icon @click="handleFoldClick" class="menu-icon">
      <expand v-if="isFold" />
      <fold v-else />
    </el-icon>

    <div class="content flex-end">
      <bread-crumb :breadcrumbs="breadcrumbs" class="hidden-xs-only" />
      <nav-info />
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed } from "vue"
import { useRoute } from "vue-router"
import { useStore } from "@/store"

import { menuToPath } from "@/utils/map-menu"

import NavInfo from "./nav-info.vue"
import breadCrumb from "@/components/breadcrumb"

import useMenuIcon from "../hooks/useMenuIconHook"

export default defineComponent({
  components: {
    NavInfo,
    breadCrumb
  },
  emits: ["foldChange"],
  setup(props, ctx) {
    // 1.菜单icon
    const [isFold, handleFoldClick] = useMenuIcon({ emit: ctx.emit })

    // 2.获取菜单列表
    const breadcrumbs = computed(() => {
      const path = useRoute().path
      const userMenus = useStore().state.login.userMenus
      return menuToPath(userMenus, path, [])
    })

    return {
      isFold,
      breadcrumbs,
      handleFoldClick
    }
  }
})
</script>

<style scoped lang="scss">
.nav-header {
  display: flex;
  align-items: center;
  flex: 1;

  .menu-icon {
    font-size: 28px;
    cursor: pointer;
  }

  .content {
    display: flex;
    // flex-direction: row-reverse;
    justify-content: space-between;
    align-items: center;
    flex: 1;
    padding: 0 18px;
  }
}
</style>
